package com.mmaingenieria.GestorFacturacion.listener;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 * Application Lifecycle Listener implementation class Listener
 *
 */
public class Listener implements ServletContextListener {

	//Atributos
	Properties propError;
	
	
    /**
     * Default constructor. 
     */
    public Listener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent sce) 
    {		
    	//LOGGER
		Logger log = Logger.getLogger(this.getClass());
		String servletRealPath = sce.getServletContext().getRealPath("/");
		PropertyConfigurator.configure( servletRealPath + "WEB-INF/config/log4j.properties");	
    	
    	//ERROR
    	propError= new Properties();
    	String error = sce.getServletContext().getInitParameter("errores");
        try 
        {
        	propError.load(sce.getServletContext().getResourceAsStream(error));     
        } catch (IOException e)
        {
        	Logger.getLogger(Listener.class.getName()).error("Error loading errores.properties"); 
		}        
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent sce) {
        // TODO Auto-generated method stub
    }
	
}
